package com.jhz.speedy.component.control;


import com.jhz.speedy.component.application.MyApplication;
import com.jhz.speedy.component.db.DbManage;
import com.jhz.speedy.component.net.ActionCallBack;
import com.jhz.speedy.component.net.NetManager;
import com.jhz.speedy.component.sound.PlaySound;

import retrofit2.Call;

/**
 * 网络请求控制器
 *
 * Created by JunHeZ on 2017/6/28.
 */
public class MyControl {
    /**===================== 数据库管理类 =====================*/
    private static DbManage dbManage;

    /**===================== Activity页面管理类 =====================*/
    private static ActivityManage activityManage;

    /**===================== 版本管理器 =====================*/
    private static VersionsManage versionsManage;

    /**===================== 声音播放器 =====================*/
    private static PlaySound playSound;

    /**===================== 接口服务 =====================*/


    /**
     * @return  数据库管理工具
     */
    public static DbManage getDbManage(){
        if(dbManage == null)
            dbManage = DbManage.getInstance();

        return dbManage;
    }

    /**
     * @return Activity页面管理类
     */
    public static ActivityManage getActivityManage(){
        if(activityManage == null)
            activityManage = ActivityManage.getInstance();

        return activityManage;
    }

    /**
     * @return  版本管理器
     */
    public static VersionsManage getVersionsManage(){
        if(versionsManage == null)
            versionsManage = VersionsManage.getInstance();

        return versionsManage;
    }

    /**
     * @return  获取声音播放器
     */
    public static PlaySound getPlaySound(){
        if(playSound == null)
            playSound = PlaySound.getInstance(MyApplication.getInstance());

        return playSound;
    }


    /**
     * 请求服务器
     * @param call  请求实体
     * @param apiName   接口名
     * @param callBack  回调
     */
    public static void callService(Call call, String apiName, ActionCallBack callBack){
        NetManager.getInstance().callService(call, apiName, callBack);
    }

    /**
     * 请求服务器
     * @param call  请求实体
     * @param apiName   接口名
     * @param isAutoToast  是否自动提示
     * @param callBack  回调
     */
    public static void callService(Call call, String apiName, boolean isAutoToast,  ActionCallBack callBack){
        NetManager.getInstance().callService(call, apiName, isAutoToast, callBack);
    }

}
